package cn.fl.project.service.impl;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.upload.api.IUploadApiService;
import cmm.comm.facade.upload.condition.SysUlDatCfgQueryCondition;
import cmm.comm.facade.upload.condition.SysUlFilesRecQueryCondition;
import cmm.comm.facade.upload.dto.SysUlDatCfgDTO;
import cmm.comm.facade.upload.dto.SysUlDatCfgDtlDTO;
import cmm.comm.facade.upload.dto.SysUlFilesRecDTO;
import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.cmm.cache.framework.utils.PropertiesCacheUtils;
import cn.fl.capital.condition.CapPayInfoQueryCondition;
import cn.fl.capital.constant.CapitalConstant;
import cn.fl.capital.vo.CapPayMaterialVo;
import cn.fl.changeapply.api.IPrjPrdChangeApplyApiService;
import cn.fl.changeapply.condition.PrjPrdChangeApplyQC;
import cn.fl.changeapply.constant.PrjPrdChangeApplyConstant;
import cn.fl.changeapply.dto.PrjPrdChangeApplyDTO;
import cn.fl.commons.result.ResponseData;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.preloan.IProprdLicenseService;
import cn.fl.preloan.dto.AddPrjPrdLicInfoRequest;
import cn.fl.preloan.dto.AddPrjPrdLicInfoResponseDTO;
import cn.fl.preloan.dto.ModifyPrjPrdLicInfoRequest;
import cn.fl.preloan.enums.PreloanResultCodeEnum;
import cn.fl.project.api.IProjectQueryApiService;
import cn.fl.project.condition.PrjPrdLicInfoQueryCondition;
import cn.fl.project.constant.PrjBscInfoConstant;
import cn.fl.project.constant.PrjPrdBscInfoConstant;
import cn.fl.project.constant.PrjPrdLicInfoConstant;
import cn.fl.project.constant.PrjPrdMtgConstant;
import cn.fl.project.dto.PrjBscInfoDTO;
import cn.fl.project.dto.PrjPrdDtlDTO;
import cn.fl.project.dto.PrjPrdLicInfoDTO;
import cn.fl.project.service.IPrjPrdLicInfoService;
import cn.fl.project.service.IProjectApiService;
import cn.fl.project.transform.PrjPrdLicInfoVOTransform;
import cn.fl.project.vo.PrjPrdLicInfoVO;
import cn.fl.system.service.ISysUlDatCfgService;
import cn.fl.system.transform.SysUlFilesRecVOTransform;
import cn.fl.system.vo.SysUlDatCfgVO;
import cn.fl.system.vo.SysUlFilesRecVO;
import cn.fl.upload.constant.UploadConstant;
import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Description: 项目车辆上牌信息表 客户端服务层接口实现
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Service
public class PrjPrdLicInfoServiceImpl implements IPrjPrdLicInfoService {

	/**
	 * 日志
	 */
	private static final Logger logger = LoggerFactory.getLogger(IPrjPrdLicInfoService.class);
	
	/**
	 * TODO 自定义 API 暴露服务
	 */
	@Autowired
	private IProjectApiService projectApiService;
	@Autowired
	private IUploadApiService uploadApiService;
	@Autowired
	private ISysUlDatCfgService sysUlDatCfgService;
	@Autowired
	private IProjectQueryApiService projectQueryApiService;
	@Autowired
    private ISysDictionaryApiService sysDictionaryApiService;
	@Autowired
	private IProprdLicenseService iProprdLicenseService;

	@Autowired
	private IPrjPrdChangeApplyApiService prjPrdChangeApplyApiService;

	//上牌资料配置编码
    public static final String CODE_LIC_FILE_CFG_CD="PRJ006";
    
	@Override
	public PrjPrdLicInfoVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "selectById", "主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		//TODO 业务逻辑
		PrjPrdLicInfoDTO dto =this.projectApiService.selectPrjPrdLicInfoById(id,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd());
		return PrjPrdLicInfoVOTransform.toVO(dto);
	}

	@Override
	public Long add(PrjPrdLicInfoVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "add", "新增对象不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		AddPrjPrdLicInfoRequest request = new AddPrjPrdLicInfoRequest();
		cn.fl.preloan.dto.PrjPrdLicInfoDTO  prdLicInfoDTO = new cn.fl.preloan.dto.PrjPrdLicInfoDTO ();
		BeanUtils.copyProperties(entity,prdLicInfoDTO);
		request.setDto(prdLicInfoDTO);
		Long start = System.currentTimeMillis();
		BaseLogUtils.info(logger, "add", "贷前服务-上牌添加调用开始");
		ResponseData<AddPrjPrdLicInfoResponseDTO> responseData = iProprdLicenseService.addPrjPrdLicInfo(request);
		BaseLogUtils.newLogger("贷前服务开始调用返回信息prdLicInfoDTO="+ prdLicInfoDTO.getVehNo() + "responseData=" + JSON.toJSONString(responseData)).info();
		if (PreloanResultCodeEnum.OTHER_DATA_VALIDATE_ERROR.getCode().equals(responseData.getCode())) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, responseData.getMessage());
		}
		Long id = responseData.getData().getId();
		BaseLogUtils.info(logger, "add", "贷前服务-上牌添加调用,用时：" + (System.currentTimeMillis() - start));
		//附件信息维护
		if(CollectionUtils.isNotEmpty(entity.getUploadFilesRecVOs())){
			String orgCd = PrjBscInfoConstant.CODE_PRJ_FILE_DEF_ORG;
			//查询项目的事业部
			PrjPrdDtlDTO dtl = this.projectApiService.selectPrjPrdDtlById(entity.getId());
			if(null!=dtl){
				PrjBscInfoDTO prjBsc = 	this.projectApiService.selectPrjBscInfoById(dtl.getPrjId(), CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
				if(null!=prjBsc){
					orgCd = prjBsc.getBuOrgCd();
				}
			}
			//查询文件主code
			SysUlDatCfgQueryCondition qc = new SysUlDatCfgQueryCondition();
					List<String> codeList = new ArrayList<String>();
					codeList.add(PrjPrdLicInfoConstant.PRJ_PRD_LIC_FILE_CODE);
					qc.setCfgCdList(codeList);
			      qc.setOrgCd(orgCd);
				qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
				String  sysCdStr = "";
				String orgCdStr = "";
				List<SysUlDatCfgVO> cfgList = sysUlDatCfgService.searchList(qc);	
		/*		List<SysUlDatCfgDtlVO> dtlList = cfgList.get(0).getSysUlDatCfgDtlVOList();
				for (SysUlDatCfgDtlVO sysUlDatCfgDtlVO : dtlList) {
					if(sysUlDatCfgDtlVO.getCfgDtlCd().equals(PrjPrdLicInfoConstant.PRJ_PRD_LIC_FILE_DETAIL_CODE)){
						sysCdStr = sysUlDatCfgDtlVO.getSysCd();
						orgCdStr = sysUlDatCfgDtlVO.getOrgCd();
						break;
					}
				}
				*/
				sysCdStr = cfgList.get(0).getSysCd();
				orgCdStr = cfgList.get(0).getOrgCd();
			
			List<SysUlFilesRecVO>  sysUlFilesRecVOs = entity.getUploadFilesRecVOs();
			for(SysUlFilesRecVO sysUlFilesRecVO:sysUlFilesRecVOs){
				sysUlFilesRecVO.setPkId(String.valueOf(id));
				sysUlFilesRecVO.setTabNm("PRJ_PRD_LIC_INFO");
				sysUlFilesRecVO.setAbsLocPath(PropertiesCacheUtils.getProperty(UploadConstant.UPLOAD_ROOT_PATH)+sysUlFilesRecVO.getFilePath());
				sysUlFilesRecVO.setIsDel(BaseConstant.IS_YESNO_NO);
				sysUlFilesRecVO.setOrgCd(orgCdStr);
				sysUlFilesRecVO.setSysCd(sysCdStr);
				sysUlFilesRecVO.setCfgCd(PrjPrdLicInfoConstant.PRJ_PRD_LIC_FILE_CODE);
				sysUlFilesRecVO.setCfgDtlCd(PrjPrdLicInfoConstant.PRJ_PRD_LIC_FILE_DETAIL_CODE);
			}
			this.uploadApiService.addSysUlFilesRecList(SysUlFilesRecVOTransform.toDTOList(sysUlFilesRecVOs));
		}
		return id;
	}

	@Override
	public boolean removeById(Long id) throws BaseException{
		/*if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "removeById", "删除主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		return this.projectApiService.removeById(id);*/
		return false;
	}
	
	/**
     * 删除
     * @param ids
     * @return
     */
    public boolean removeByIds(List<Long> ids)throws BaseException{
    	if(CollectionUtils.isEmpty(ids)){
    		BaseLogUtils.info(logger, "removeByIds", "删除主键参数集合不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		};
		return  this.projectApiService.removePrjPrdLicInfoByIds(ids);
    }

	@Override
	public boolean modify(PrjPrdLicInfoVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "modify", "修改对象参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		//调动贷前服务
		ModifyPrjPrdLicInfoRequest request = new ModifyPrjPrdLicInfoRequest();
		cn.fl.preloan.dto.PrjPrdLicInfoDTO prjPrdLicOrgDTO = new cn.fl.preloan.dto.PrjPrdLicInfoDTO();
		BeanUtils.copyProperties(entity,prjPrdLicOrgDTO);
		request.setDto(prjPrdLicOrgDTO);
		boolean flag = false;
		Long start = System.currentTimeMillis();
		BaseLogUtils.newLogger("贷前服务modifyPrjPrdLicInfo开始调用").info();
		ResponseData responseData = this.iProprdLicenseService.modifyPrjPrdLicInfo(request);
		BaseLogUtils.newLogger("贷前服务开始调用返回信息prjPrdLicOrgDTO="+ prjPrdLicOrgDTO.getVehNo() + "responseData=" + JSON.toJSONString(responseData)).info();
		if (PreloanResultCodeEnum.OTHER_DATA_VALIDATE_ERROR.getCode().equals(responseData.getCode())) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, responseData.getMessage());
		}
		if (responseData.getCode().equals(PreloanResultCodeEnum.SUCCESS.getCode())){
			flag = true;
			BaseLogUtils.info(logger,"modify","贷前服务调用成功，耗时：：" + (System.currentTimeMillis() - start)/1000 + "s");
		}
		if(CollectionUtils.isNotEmpty(entity.getUploadFilesRecVOs())){
			 String orgCd = PrjBscInfoConstant.CODE_PRJ_FILE_DEF_ORG;
				//查询项目的事业部
				PrjPrdDtlDTO dtl = this.projectApiService.selectPrjPrdDtlById(entity.getId());
				if(null!=dtl){
					PrjBscInfoDTO prjBsc = 	this.projectApiService.selectPrjBscInfoById(dtl.getPrjId(), CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
					if(null!=prjBsc){
						orgCd = prjBsc.getBuOrgCd();
					}
				}
				//查询文件主code
				SysUlDatCfgQueryCondition qc = new SysUlDatCfgQueryCondition();
						List<String> codeList = new ArrayList<String>();
						codeList.add(PrjPrdLicInfoConstant.PRJ_PRD_LIC_FILE_CODE);
						qc.setCfgCdList(codeList);
				      qc.setOrgCd(orgCd);
					qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
					String  sysCdStr = "";
					String orgCdStr = "";
					List<SysUlDatCfgVO> cfgList = sysUlDatCfgService.searchList(qc);	
					/*			List<SysUlDatCfgDtlVO> dtlList = cfgList.get(0).getSysUlDatCfgDtlVOList();
				for (SysUlDatCfgDtlVO sysUlDatCfgDtlVO : dtlList) {
						if(sysUlDatCfgDtlVO.getCfgDtlCd().equals(PrjPrdLicInfoConstant.PRJ_PRD_LIC_FILE_DETAIL_CODE)){
							sysCdStr = sysUlDatCfgDtlVO.getSysCd();
							orgCdStr = sysUlDatCfgDtlVO.getOrgCd();
							break;
						}
					}*/
					sysCdStr = cfgList.get(0).getSysCd();
					orgCdStr = cfgList.get(0).getOrgCd();
			//删除之前的附件信息
			SysUlFilesRecQueryCondition	fileQc = new SysUlFilesRecQueryCondition();
			fileQc.setSysCd(CurrentThreadContext.getCurrentSysCd());
			fileQc.setPkId(String.valueOf(entity.getId()));
			fileQc.setTabNm("PRJ_PRD_LIC_INFO");
			fileQc.setOrgCd(orgCdStr);
			fileQc.setSysCd(sysCdStr);
			fileQc.setCfgCd(PrjPrdLicInfoConstant.PRJ_PRD_LIC_FILE_CODE);
			fileQc.setCfgDtlCd(PrjPrdLicInfoConstant.PRJ_PRD_LIC_FILE_DETAIL_CODE);
			List<SysUlFilesRecVO> fileList = SysUlFilesRecVOTransform.toVOList(this.uploadApiService.searchSysUlFilesRecList(fileQc));
			List<Long> idList = new ArrayList<Long>();
			if(CollectionUtils.isNotEmpty(fileList)){
				for (SysUlFilesRecVO sysUlFilesRecVO : fileList) {
					idList.add(sysUlFilesRecVO.getId());
				}
				this.uploadApiService.removeSysUlFilesRecByIds(idList);
			}
		
				
			
			//附件信息维护
			List<SysUlFilesRecVO>  sysUlFilesRecVOs = entity.getUploadFilesRecVOs();
			for(SysUlFilesRecVO sysUlFilesRecVO:sysUlFilesRecVOs){
			sysUlFilesRecVO.setPkId(String.valueOf(entity.getId()));
			sysUlFilesRecVO.setTabNm("PRJ_PRD_LIC_INFO");
			sysUlFilesRecVO.setIsDel(BaseConstant.IS_YESNO_NO);
			sysUlFilesRecVO.setAbsLocPath(PropertiesCacheUtils.getProperty(UploadConstant.UPLOAD_ROOT_PATH)+sysUlFilesRecVO.getFilePath());

			sysUlFilesRecVO.setOrgCd(orgCdStr);
			sysUlFilesRecVO.setSysCd(sysCdStr);
			sysUlFilesRecVO.setCfgCd(PrjPrdLicInfoConstant.PRJ_PRD_LIC_FILE_CODE);
			sysUlFilesRecVO.setCfgDtlCd(PrjPrdLicInfoConstant.PRJ_PRD_LIC_FILE_DETAIL_CODE);
			}
			this.uploadApiService.addSysUlFilesRecList(SysUlFilesRecVOTransform.toDTOList(sysUlFilesRecVOs));
		}
				return flag;
	}

	@Override
	public boolean modifyVehNo(PrjPrdLicInfoVO entity)throws BaseException {
		return this.projectApiService.modifyVehNo(PrjPrdLicInfoVOTransform.toDTO(entity));
	}

	@Override
	public Pager searchListPage(Pager page) throws BaseException{
		if(null == page)page = new Pager();
	
		Pager pager = 	projectApiService.searchPrjPrdLicInfoListPage(page, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
		List<PrjPrdLicInfoVO> list = PrjPrdLicInfoVOTransform.toVOList((List<PrjPrdLicInfoDTO>)pager.getResultList());
		pager.setResultList(list);
		return pager;
	}
	
	@Override
	public List<PrjPrdLicInfoVO> searchList(PrjPrdLicInfoQueryCondition qc) throws BaseException{
		return PrjPrdLicInfoVOTransform.toVOList(projectApiService.prjPrdLicInfoSearchList(qc, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd()));
	}

	@Override
	public List<PrjPrdLicInfoVO> searchInitPrjPrdDtlList(Long dtlId) throws BaseException {
		
		return PrjPrdLicInfoVOTransform.toVOList(this.projectQueryApiService.searchInitPrjPrdDtlList(dtlId));
	}
	
	
	
	//抵押管理或上牌管理，获取上传的历史附件
	public List<SysUlDatCfgDTO> getOldMateList(String orgCd,CapPayInfoQueryCondition condition,String from) throws BaseException {
		
		SysUlDatCfgQueryCondition ulDatCfgQueryCondition = new SysUlDatCfgQueryCondition();
		
		List<String> cfgCdList = new ArrayList<>();
		if("mtg".equals(from)) {
			cfgCdList.add(PrjPrdMtgConstant.PRJ_PRD_MTG_FILE_CODE);//历史数据存在《抵押信息-其他》 PRJ007
		}else {
			cfgCdList.add(PrjPrdLicInfoServiceImpl.CODE_LIC_FILE_CFG_CD);//历史数据存在《上牌资料-其他》 PRJ006
		}
		
		ulDatCfgQueryCondition.setCfgCdList(cfgCdList);
		ulDatCfgQueryCondition.setDataId(String.valueOf(condition.getPrjPrdDtlId()));
		ulDatCfgQueryCondition.setOrgCd(orgCd);//组织架构代码
		ulDatCfgQueryCondition.setSysCd(CurrentThreadContext.getCurrentSysCd());
		
		return uploadApiService.searchSysUlDatCfgListByDataId(ulDatCfgQueryCondition);
	}
	
	//抵押管理或上牌管理，获取上传的新的附件
	public List<SysUlDatCfgDTO> getNewMateList(String orgCd,CapPayInfoQueryCondition condition,String from) throws BaseException {
		
		SysUlDatCfgQueryCondition ulDatCfgQueryCondition = new SysUlDatCfgQueryCondition();
		
		List<String> cfgCdList = new ArrayList<>();
		cfgCdList.add(CapitalConstant.CODE_UL_PAY_FILE_CFG_CD);//放款资料配置编码:PRJ015
		
		ulDatCfgQueryCondition.setCfgCdList(cfgCdList);
		ulDatCfgQueryCondition.setDataId(String.valueOf(condition.getPrjPrdDtlId()));
		ulDatCfgQueryCondition.setOrgCd(orgCd);//组织架构代码
		ulDatCfgQueryCondition.setSysCd(CurrentThreadContext.getCurrentSysCd());
		
		return uploadApiService.searchSysUlDatCfgListByDataId(ulDatCfgQueryCondition);
	}
		
	public List<CapPayMaterialVo> searchMateList(CapPayInfoQueryCondition condition,String from) throws BaseException {
		
		//查询项目的事业部
		String cstMgrOrgCd = PrjBscInfoConstant.CODE_PRJ_FILE_DEF_ORG;
		String buOrgCd = PrjBscInfoConstant.CODE_PRJ_FILE_DEF_ORG;
		
		PrjPrdDtlDTO prjPrdDtlDTO = this.projectApiService.selectPrjPrdDtlById(condition.getPrjPrdDtlId());
		PrjBscInfoDTO prjBscInfoDTO = new PrjBscInfoDTO();
		if(null!=prjPrdDtlDTO){
			Long prjId = prjPrdDtlDTO.getPrjId();
			//换车需求，dtl表开始没有prjId
			if (prjId == null) {
				PrjPrdChangeApplyQC prjPrdChangeApplyQC = new PrjPrdChangeApplyQC();
				prjPrdChangeApplyQC.setNewPrjPrdDtlId(condition.getPrjPrdDtlId());
				prjPrdChangeApplyQC.setChangeTypeCd(PrjPrdChangeApplyConstant.CHANGE_TYPE_CD_2);
				prjPrdChangeApplyQC.setIsDel(0);
				List<PrjPrdChangeApplyDTO> dtoList = this.prjPrdChangeApplyApiService.selectList(prjPrdChangeApplyQC, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
				if (CollectionUtils.isNotEmpty(dtoList)) {
					prjId = dtoList.get(0).getPrjId();
				}
			}
			prjBscInfoDTO = this.projectApiService.selectPrjBscInfoById(prjId, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
			if(null!=prjBscInfoDTO && StringUtils.isNotBlank(prjBscInfoDTO.getBuOrgCd())){
				cstMgrOrgCd = prjBscInfoDTO.getCstMgrOrgCd();
				buOrgCd = prjBscInfoDTO.getBuOrgCd();
				//如果是专车事业部00000008，则修改为专车-客车融资000000080002,因为专车事业部没有配置资料项+；后期优化数据应来自规则引擎
//				if("00000008".equals(buOrgCd)) {
//					buOrgCd = "000000080002";
//				}
			}
		}
		
		
		List<SysUlDatCfgDTO> oldSysUlDatCfgDTOList = this.getOldMateList(cstMgrOrgCd, condition, from);
		List<SysUlDatCfgDTO> newSysUlDatCfgDTOList = this.getNewMateList(cstMgrOrgCd, condition, from);
		
		List<SysUlDatCfgDTO> allSysUlDatCfgDTOList = new ArrayList<SysUlDatCfgDTO>();
		if (CollectionUtils.isNotEmpty(oldSysUlDatCfgDTOList)) {
			this.removeEmptyForSysUlDatCfgDTO(oldSysUlDatCfgDTOList);//去掉没有上传附件的配置编码明细
			allSysUlDatCfgDTOList.addAll(oldSysUlDatCfgDTOList);
		}
		if (CollectionUtils.isNotEmpty(newSysUlDatCfgDTOList)) {
			allSysUlDatCfgDTOList.addAll(newSysUlDatCfgDTOList);
		}

		List<CapPayMaterialVo> voList = null;
		if (CollectionUtils.isNotEmpty(allSysUlDatCfgDTOList)) {
			Map<String, String> audStsCdMap = this.sysDictionaryApiService.searchGroupToMap(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), CapitalConstant.CODE_MATE_AUD_STS_CD);
			voList = new ArrayList<>();
			
			//设置路径
			String picServicePath = PropertiesCacheUtils.getProperty(UploadConstant.UPLOAD_SERVER_PATH);
			for (SysUlDatCfgDTO dto : allSysUlDatCfgDTOList) {
				for (SysUlDatCfgDtlDTO dtlDTO : dto.getSysUlDatCfgDtlDTOList()) {
					
					if("mtg".equals(from)) {
						//显示放款资料PRJ015-《登记证 -车辆信息页》、《登记证-抵押我司页》《抵押信息-其他》
						//天津银行 追加显示放款资料PRJ015-440《车辆营运证》
						if (null!=prjBscInfoDTO && StringUtils.isNotBlank(prjBscInfoDTO.getInsCode()) && PrjBscInfoConstant.PRJ_INS_CODE_TIANJINBANK.equals(prjBscInfoDTO.getInsCode())){
							if((CapitalConstant.CODE_UL_PAY_FILE_CFG_CD.equals(dtlDTO.getCfgCd())
									&& ("241".equals(dtlDTO.getCfgDtlCd())
									|| "242".equals(dtlDTO.getCfgDtlCd())
									|| "440".equals(dtlDTO.getCfgDtlCd()))) ||
									(PrjPrdMtgConstant.PRJ_PRD_MTG_FILE_CODE.equals(dtlDTO.getCfgCd())
											&& "10".equals(dtlDTO.getCfgDtlCd()))) {
								this.setCapPayMaterialVo(dtlDTO, dto, picServicePath, audStsCdMap, voList);
							}
						}else {
							if((CapitalConstant.CODE_UL_PAY_FILE_CFG_CD.equals(dtlDTO.getCfgCd())
									&& ("241".equals(dtlDTO.getCfgDtlCd())
									|| "242".equals(dtlDTO.getCfgDtlCd()))) ||
									(PrjPrdMtgConstant.PRJ_PRD_MTG_FILE_CODE.equals(dtlDTO.getCfgCd())
											&& "10".equals(dtlDTO.getCfgDtlCd()))) {
								this.setCapPayMaterialVo(dtlDTO, dto, picServicePath, audStsCdMap, voList);
							}
						}
					}else {
						//显示放款资料PRJ015-行驶证13 和上牌历史资料PRJ006
						if((CapitalConstant.CODE_UL_PAY_FILE_CFG_CD.equals(dtlDTO.getCfgCd()) 
								&& "13".equals(dtlDTO.getCfgDtlCd())) ||
								PrjPrdLicInfoServiceImpl.CODE_LIC_FILE_CFG_CD.equals(dtlDTO.getCfgCd())) {
							this.setCapPayMaterialVo(dtlDTO, dto, picServicePath, audStsCdMap, voList);
						}
					}
				}
			}
		}
		return voList;
	}
	
	//去掉removeEmptyForSysUlDatCfgDTO的空值
	private void removeEmptyForSysUlDatCfgDTO(List<SysUlDatCfgDTO> sysUlDatCfgDTOList) {
		
		if(sysUlDatCfgDTOList != null && sysUlDatCfgDTOList.size() >0) {
			for (SysUlDatCfgDTO sysUlDatCfgDTO : sysUlDatCfgDTOList) {
				List<SysUlDatCfgDtlDTO> sysUlDatCfgDtlDTOList = sysUlDatCfgDTO.getSysUlDatCfgDtlDTOList();
				if(sysUlDatCfgDtlDTOList != null && sysUlDatCfgDtlDTOList.size()>0) {
					
					List<SysUlDatCfgDtlDTO> newSysUlDatCfgDtlDTOList = new ArrayList<SysUlDatCfgDtlDTO>();
					for (SysUlDatCfgDtlDTO sysUlDatCfgDtlDTO : sysUlDatCfgDtlDTOList) {
						if(StringUtils.isNotEmpty(sysUlDatCfgDtlDTO.getFilePath())) {
							//存在上传文件，则保留对象
							newSysUlDatCfgDtlDTOList.add(sysUlDatCfgDtlDTO);
						}
					}
					
					sysUlDatCfgDTO.setSysUlDatCfgDtlDTOList(newSysUlDatCfgDtlDTOList);
				}
			}
		}
		
	}
	
	
	private void setCapPayMaterialVo(SysUlDatCfgDtlDTO dtlDTO,SysUlDatCfgDTO dto,String picServicePath,Map<String, String> audStsCdMap,List<CapPayMaterialVo> voList) {
		CapPayMaterialVo vo = new CapPayMaterialVo();
//		vo.setId(condition.getId());
		vo.setCfgDtlCd(dtlDTO.getCfgDtlCd());//配置子编号
		vo.setDatNm(dtlDTO.getDatNm());//配置名称
		vo.setCfgCd(dtlDTO.getCfgCd());//配置编号
		vo.setCfgNm(dto.getCfgNm());//配置子名称
		vo.setFileId(dtlDTO.getRecId());//附件ID
		//如果有HTTP开头说明是可以访问路径,无需干涉
		if(StringUtils.isNotBlank(dtlDTO.getFilePath())&&!dtlDTO.getFilePath().startsWith("http") && StringUtils.isNotBlank(picServicePath)){
			vo.setFilePath(picServicePath+dtlDTO.getFilePath());
		}else{
			vo.setFilePath(dtlDTO.getFilePath());//附件路径
		}
		vo.setFileNm(dtlDTO.getRecFileNm());//上传名称
		vo.setCrtTm(dtlDTO.getRecCrtTm());//上传时间
		vo.setOrgCd(dtlDTO.getOrgCd());//机构代码
		vo.setSysCd(dtlDTO.getSysCd());//系统代码
		//是否必传
		vo.setIsMust(dtlDTO.getIsMust());
		if (StringUtils.isNotBlank(dtlDTO.getRecAudStsCd())) {
			vo.setAudStsCd(dtlDTO.getRecAudStsCd());//验证状态
		} else {
			vo.setAudStsCd("0");//验证状态
		}

		if (audStsCdMap != null && audStsCdMap.containsKey(vo.getAudStsCd())) {
			vo.setAudStsCdNm(audStsCdMap.get(vo.getAudStsCd()));
		}
		voList.add(vo);
	}

	@Override
	public void modifyFileState(String id) throws BaseException {
		
		SysUlFilesRecQueryCondition qc = new SysUlFilesRecQueryCondition();
		qc.setPkId(id);//上牌id=项目产品明细id
		qc.setCfgCd(PrjBscInfoConstant.CODE_PRJ_PRD_FILE_CD);
		qc.setCfgDtlCd("13");
		qc.setTabNm(PrjPrdBscInfoConstant.PRJ_PRD_FILE_VEH_PHOTO_TABLE_NM);
		qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
		
		List<SysUlFilesRecDTO> sysUlFilesRecDTOList = this.uploadApiService.searchSysUlFilesRecList(qc);
		BaseLogUtils.info(logger, null, "sysUlFilesRecDTOList:" + JSON.toJSONString(sysUlFilesRecDTOList));
		if(sysUlFilesRecDTOList != null && sysUlFilesRecDTOList.size() >0) {
			for (SysUlFilesRecDTO sysUlFilesRecDTO : sysUlFilesRecDTOList) {
				sysUlFilesRecDTO.setAudStsCd("1");//验证通过
			}
			
			this.uploadApiService.modifySysUlFilesRecList(sysUlFilesRecDTOList);
		}
	}
}
